"""'create_order_table'

Revision ID: 46c77790af7f
Revises: 4c762d690ca9
Create Date: 2017-05-02 17:26:28.260064

"""

# revision identifiers, used by Alembic.
revision = '46c77790af7f'
down_revision = '4c762d690ca9'

from alembic import op
import sqlalchemy as sa
import enum
class NotifyMethod(enum.Enum):
    email = 'email'
    url = 'url'


class OrderStatus(enum.Enum):
    created = 'created'
    paid = 'paid'
    canceled = 'canceled'
    ended = 'ended'
    removed = 'removed'
    shipped = 'shipped'
    shipping = 'shipping'
    confirmed = 'confirmed'
    returned = 'returned'
    pay_error = 'pay_error'


class DeliveryMethod(enum.Enum):
    ticket = 'ticket'



def upgrade():
    ### commands auto generated by Alembic - please adjust! ###
    op.create_table('order',
    sa.Column('id', sa.Integer(), nullable=False,autoincrement=True),
    sa.Column('description', sa.String(length=200), nullable=True),
    sa.Column('remark', sa.String(length=800), nullable=True),
    sa.Column('member_id', sa.String(length=80), nullable=True),
    sa.Column('status', sa.String(30), nullable=False),
    sa.Column('fee', sa.Numeric(precision=15, scale=4), nullable=True),
    sa.Column('real_fee', sa.Numeric(precision=15, scale=4), nullable=True),
    sa.Column('amount', sa.Numeric(precision=15, scale=4), nullable=False),
    sa.Column('real_amount', sa.Numeric(precision=15, scale=4), nullable=False),
    sa.Column('payment_method', sa.String(length=80), nullable=True),
    sa.Column('trade_id', sa.String(length=100), nullable=False),
    sa.Column('payment_seq', sa.String(length=120), nullable=True),
    sa.Column('created_at', sa.DateTime(), nullable=False),
    sa.Column('updated_at', sa.DateTime(), nullable=False),
    sa.Column('expire_time', sa.DateTime(), nullable=True),
    sa.Column('settle_time', sa.DateTime(), nullable=True),
    sa.Column('currency_id', sa.String(length=40), nullable=False),
    sa.Column('notify_method', sa.String(30), nullable=True),
    sa.Column('notify_info', sa.String(length=400), nullable=True),
    sa.Column('parent_id', sa.Integer(), nullable=True),
    sa.Column('dealer_id', sa.String(length=80), nullable=False),

    sa.ForeignKeyConstraint(['currency_id'], ['currency.id'], ),
    sa.ForeignKeyConstraint(['member_id'], ['member.id'], ),
    sa.ForeignKeyConstraint(['parent_id'], ['order.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('order_detail',
    sa.Column('id', sa.Integer(), nullable=False,autoincrement=True),
    sa.Column('count', sa.Integer(), nullable=False),
    sa.Column('amount', sa.Numeric(precision=15, scale=4), nullable=False),
    sa.Column('product_id', sa.String(length=200), nullable=False),
    sa.Column('order_id', sa.Integer(), nullable=False),
    sa.Column('real_amount', sa.Numeric(precision=15, scale=4), nullable=True),
    sa.Column('delivery_method', sa.String(30), nullable=True),
    sa.Column('delivery_id', sa.String(length=120), nullable=True),
    # sa.ForeignKeyConstraint(['dealer_id'], ['member.id'], ),
    sa.ForeignKeyConstraint(['order_id'], ['order.id'], ),
    sa.ForeignKeyConstraint(['product_id'], ['product.id'], ),
    sa.PrimaryKeyConstraint('id'))
    op.create_table('order_detail_additional',
    sa.Column('id', sa.Integer(), nullable=False,autoincrement=True,primary_key=True),
    sa.Column('order_detail_id', sa.Integer(), nullable=False),
    sa.Column('count', sa.Integer(), nullable=False),
    sa.Column('amount', sa.Numeric(precision=15, scale=4), nullable=False),
    sa.Column('additional_id', sa.String(length=40), nullable=False),
    sa.ForeignKeyConstraint(['additional_id'], ['additional_item.id'], ),
    sa.ForeignKeyConstraint(['order_detail_id'], ['order_detail.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    # op.alter_column('auth', 'profile_id',
    #            existing_type=sa.VARCHAR(length=400),
    #            nullable=False)
    # op.alter_column('product_gallery', 'product_id',
    #            existing_type=sa.VARCHAR(length=200),
    #            nullable=True)
    # op.alter_column('product_gallery', 'resource_id',
    #            existing_type=sa.VARCHAR(length=42),
    #            nullable=True)
    ### end Alembic commands ###


def downgrade():
    ### commands auto generated by Alembic - please adjust! ###
    # op.alter_column('product_gallery', 'resource_id',
    #            existing_type=sa.VARCHAR(length=42),
    #            nullable=False)
    # op.alter_column('product_gallery', 'product_id',
    #            existing_type=sa.VARCHAR(length=200),
    #            nullable=False)
    # op.alter_column('auth', 'profile_id',
    #            existing_type=sa.VARCHAR(length=400),
    #            nullable=True)
    op.drop_table('order_detail_additional')
    op.drop_table('order_detail')
    op.drop_table('order')
    ### end Alembic commands ###
